<template>
  <a-modal
    :title="title"
    width="68%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="
      () => {
        this.visible = false
      }
    "
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="服务项目" prop="Name">
          <a-input v-model="entity.Name" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="项目详情" prop="Content">
          <wang-editor v-model="entity.Content"></wang-editor>
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import store from '@/store'
import WangEditor from '@/components/WangEditor/WangEditor'

export default {
  props: {
    parentObj: Object,
  },
  components: {
    WangEditor,
  },
  data() {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 },
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: '',
    }
  },
  methods: {
    init() {
      this.visible = true
      this.entity = { Content: 'test', Name: 'test' }
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm(content, title) {
      this.init()

      if (content) {
        console.log(content)
        this.entity = content
      }
    },
    handleSubmit() {
      this.$refs['form'].validate((valid) => {
        if (!valid) {
          return
        }
        this.visible = false
      })
    },
  },
}
</script>
